﻿using System;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YJKRevitView;
using YJKRevitStairs.StairsModel.Manage;

namespace YJKRevitStairs.StairsModel
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class CmdCreateLinearDoubleRunStairs : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			Result result;
			try
			{
				if (Convert.ToInt32(commandData.Application.Application.VersionNumber) < 2014)
				{
					message = "此功能只在Revit2014及其以上版本可用。";
					result = Autodesk.Revit.UI.Result.Failed;
				}
				else
				{
					CmdViewType types = (CmdViewType)11;
					if (SwitchView.SetUsableView(types, commandData) != Autodesk.Revit.UI.Result.Succeeded)
					{
						result = Autodesk.Revit.UI.Result.Failed;
					}
					else
					{
						HideWarningKit @object = new HideWarningKit("delete temp levels");
						commandData.Application.Application.FailuresProcessing += @object.OnFailuresProcessing;
						HideWarningKit object2 = new HideWarningKit("Stairs Automation");
						commandData.Application.Application.FailuresProcessing += object2.OnFailuresProcessing;
						HideWarningKit object3 = new HideWarningKit("change type");
						commandData.Application.Application.FailuresProcessing += object3.OnFailuresProcessing;
						HideWarningKit object4 = new HideWarningKit("Stairs Beam");
						commandData.Application.Application.FailuresProcessing += object4.OnFailuresProcessing;
						HideWarningKit object5 = new HideWarningKit("Delete level");
						commandData.Application.Application.FailuresProcessing += object5.OnFailuresProcessing;
						HideWarningKit object6 = new HideWarningKit("CorrectStairsHeight");
						commandData.Application.Application.FailuresProcessing += object6.OnFailuresProcessing;
						if (!new StairsManager(commandData).AddLinearDoubleRunStairs())
						{
							result = Autodesk.Revit.UI.Result.Failed;
						}
						else
						{
							result = Autodesk.Revit.UI.Result.Succeeded;
						}
					}
				}
			}
			catch (Exception)
			{
				YJKMessageBox.Show("命令执行失败！");
				result = Autodesk.Revit.UI.Result.Failed;
			}
			return result;
		}
	}
}
